const api = require('../../utils/api.js');
const app = getApp();

Page({
  data: {
    abnorData: {
      imgSrc: app.imgUrl + 'abnor-19.png',
      text: '暂无内容',
    },
    useTabbar: !(app.tabbarindex === 0 && app.siteInfo.tabbar_type === '1'),
  },

  onLoad(options) {
    let _this = this;
    let opts = options || {};
    let { id = 'about_us', type = '', status = '' } = opts;
    _this.setData({ 
      opts,
      useTabbar: _this.data.useTabbar && app.getTabBarStatus(),
    });
    wx.showLoading({
      title: '正在加载...',
      mask: true,
    });
    app.ws_micro_shoprequest({
      url:
        status === 'cashout'
          ? api.share.get_content
          : api.default.article_detail,
      data: {
        id,
        type,
      },
      success: function(res) {
        wx.hideLoading();
        let resp = res.data;
        if (!resp || resp.content === '' || resp.content === null) return;
        if (res.code === 0) {
          wx.setNavigationBarTitle({
            title: resp.title || resp.name,
          });
          _this.setData({
            content: resp.content,
          });
        }
        if (res.code === 1) {
          wx.showModal({
            title: '提示',
            content: res.msg,
            showCancel: false,
            success: function(e) {
              if (e.confirm) {
                wx.navigateBack();
              }
            },
          });
        }
      },
    });
  },

  wxmlTagATap(e) {
    let src = e.detail.src || false;
    let reUrl = /^\//;
    if (!src) {
      return;
    } else {
      reUrl.test(src)
        ? app.util.navigateTo('/ws_micro_shop' + src)
        : app.util.navigateTo('/ws_micro_shop/pages/web/web?url=' + src);
    }
  },
});
